import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Req,
} from '@nestjs/common';
import { YingpingfankuiService } from './yingpingfankui.service';
import { CreateYingpingfankuiDto } from './dto/create-yingpingfankui.dto';
import { UpdateYingpingfankuiDto } from './dto/update-yingpingfankui.dto';
import { SearchPagesDto } from './dto/search-pages.dto';
import { JwtAuthGuard } from 'src/common/guard/jwt-auth.guard';
import { Public } from 'src/common/guard/public.decorator';
import { UserEntity } from 'src/user/entities/user.entity';

@Controller('admin/yingpingfankui')
@UseGuards(JwtAuthGuard)
export class YingpingfankuiController {
  constructor(private readonly yingpingfankuiService: YingpingfankuiService) {}

  @Post()
  create(
    @Body() createYingpingfankuiDto: CreateYingpingfankuiDto,
    @Req() req: { user: UserEntity },
  ) {
    return this.yingpingfankuiService.create(createYingpingfankuiDto, req.user);
  }

  @Get()
  @Public()
  findAll() {
    return this.yingpingfankuiService.findAll();
  }

  @Get('yingpingfankui_tj_pingfen')
  @Public()
  chart() {
    return this.yingpingfankuiService.chart();
  }

  // 分页查询（带搜索条件）
  @Post('/page')
  @Public()
  findAllPage(@Body() pages: SearchPagesDto) {
    return this.yingpingfankuiService.findAllPage(pages);
  }

  @Get(':id')
  @Public()
  findOne(@Param('id') id: string) {
    return this.yingpingfankuiService.findOne(+id);
  }

  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() updateYingpingfankuiDto: UpdateYingpingfankuiDto,
  ) {
    return this.yingpingfankuiService.update(+id, updateYingpingfankuiDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.yingpingfankuiService.remove(+id);
  }
}
